package com.example.newone.controller;


import com.example.newone.dao.UserDao;
import com.example.newone.service.UserService;
import com.example.newone.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/user")
@Slf4j
@Api("用户接口")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "22222", notes = "2222")
    @GetMapping("/list")
    public R findUser(){
        log.info("开始");
        List<UserDao> user = userService.findUser();
        return R.ok().put("message",user);
    }

    @ApiOperation(value = "11111", notes = "11111")
    @GetMapping("/tree")
    public R findTree(){
        log.info("树状结构");
        List<UserDao> tree = userService.findTree();
        return R.ok().put("message",tree);
    }

    @ApiOperation(value = "3333", notes = "33333")
    @PostMapping("/add")
    public R addUser(@RequestBody UserDao userDao){
        log.info("添加");
        userService.insert(userDao);
        return R.ok().put("message","添加成功");
    }

    @ApiOperation(value = "11111", notes = "11111")
    @DeleteMapping("/delete/{id}")
    public R deleteUser(@PathVariable Long id){
        log.info("删除");
        userService.deleteUser(id);
        return R.ok().put("message","删除成功");
    }

    @ApiOperation(value = "11111", notes = "11111")
    @PostMapping("/update")
    public R updateUser(@RequestBody UserDao userDao){
        log.info("修改");
        userService.updateUser(userDao);
        return R.ok().put("message","修改成功");
    }


}
